package com.ruoyi.jiajia.controller;

import java.util.List;

import com.ruoyi.system.domain.JiajiaHospital;
import com.ruoyi.system.domain.JiajiaHospitalDepartment;
import com.ruoyi.system.service.IJiajiaHospitalDepartmentService;
import com.ruoyi.system.service.IJiajiaHospitalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院科室Controller
 * 
 * @author mrwang
 * @date 2024-05-06
 */
@Controller
@RequestMapping("/jiajia/department")
public class JiajiaHospitalDepartmentController extends BaseController
{
    private String prefix = "jiajia/department";

    @Autowired
    private IJiajiaHospitalDepartmentService jiajiaHospitalDepartmentService;
    @Autowired
    private IJiajiaHospitalService jiajiaHospitalService;

    @RequiresPermissions("system:department:view")
    @GetMapping()
    public String department()
    {
        return prefix + "/department";
    }

    /**
     * 查询医院科室列表
     */
    @RequiresPermissions("system:department:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaHospitalDepartment jiajiaHospitalDepartment)
    {
        startPage();
        List<JiajiaHospitalDepartment> list = jiajiaHospitalDepartmentService.selectJiajiaHospitalDepartmentList(jiajiaHospitalDepartment);
        return getDataTable(list);
    }

    /**
     * 导出医院科室列表
     */
    @RequiresPermissions("system:department:export")
    @Log(title = "医院科室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaHospitalDepartment jiajiaHospitalDepartment)
    {
        List<JiajiaHospitalDepartment> list = jiajiaHospitalDepartmentService.selectJiajiaHospitalDepartmentList(jiajiaHospitalDepartment);
        ExcelUtil<JiajiaHospitalDepartment> util = new ExcelUtil<JiajiaHospitalDepartment>(JiajiaHospitalDepartment.class);
        return util.exportExcel(list, "医院科室数据");
    }

    /**
     * 新增医院科室
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        //获取医院列表
        JiajiaHospital hospital = new JiajiaHospital();
        List<JiajiaHospital> hospitalList = jiajiaHospitalService.selectJiajiaHospitalList(hospital);
        mmap.put("hospitalList", hospitalList);
        return prefix + "/add";
    }

    /**
     * 新增保存医院科室
     */
    @RequiresPermissions("system:department:add")
    @Log(title = "医院科室新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaHospitalDepartment jiajiaHospitalDepartment)
    {
        return toAjax(jiajiaHospitalDepartmentService.insertJiajiaHospitalDepartment(jiajiaHospitalDepartment));
    }

    /**
     * 修改医院科室
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaHospitalDepartment jiajiaHospitalDepartment = jiajiaHospitalDepartmentService.selectJiajiaHospitalDepartmentById(id);
        mmap.put("jiajiaHospitalDepartment", jiajiaHospitalDepartment);
        JiajiaHospital hospital = new JiajiaHospital();
        List<JiajiaHospital> hospitalList = jiajiaHospitalService.selectJiajiaHospitalList(hospital);
        mmap.put("hospitalList", hospitalList);
        return prefix + "/edit";
    }

    /**
     * 修改保存医院科室
     */
    @RequiresPermissions("system:department:edit")
    @Log(title = "医院科室编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaHospitalDepartment jiajiaHospitalDepartment)
    {
        return toAjax(jiajiaHospitalDepartmentService.updateJiajiaHospitalDepartment(jiajiaHospitalDepartment));
    }

    /**
     * 删除医院科室
     */
    @RequiresPermissions("system:department:remove")
    @Log(title = "医院科室删除", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaHospitalDepartmentService.deleteJiajiaHospitalDepartmentByIds(ids));
    }

}
